package com.jiangyg.mall.ware.controller;

import com.jiangyg.mall.core.support.restful.Pagination;
import com.jiangyg.mall.core.support.restful.Result;
import com.jiangyg.mall.ware.dto.WareInfoDTO;
import com.jiangyg.mall.ware.service.WareInfoService;
import com.jiangyg.mall.ware.vo.WareInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 类描述：仓库信息控制器
 *
 * @author jiangyg
 * @version email@jiangyg.com
 * @date 2021-10-30 07:41:17
 */
@RestController
@RequestMapping("/ware/wareinfo")
public class WareInfoController {

    /**
     * 仓库信息接口
     */
    private final WareInfoService wareInfoService;

    @Autowired
    public WareInfoController(WareInfoService wareInfoService) {
        this.wareInfoService = wareInfoService;
    }

    /**
     * 功能描述：仓库信息分页查询
     *
     * @param request    请求
     * @param pagination 分页参数
     * @return 返回分页仓库信息
     */
    @ResponseBody
    @PostMapping("/select")
    public Result<Pagination<WareInfoVO>> select(HttpServletRequest request, @RequestBody Pagination<WareInfoVO> pagination) throws Exception {
        return Result.ok(wareInfoService.selectPagination(pagination));
    }

    /**
     * 功能描述：保存或者修改仓库信息
     *
     * @param request 请求
     * @param dto     仓库信息
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/save")
    public Result<Object> save(HttpServletRequest request, @RequestBody @Validated WareInfoDTO dto) throws Exception {
        return Result.saveOrUpdate(wareInfoService.saveOrUpdate(dto));
    }

    /**
     * 功能描述：根据ID获取仓库信息
     *
     * @param request    请求
     * @param wareInfoId 仓库信息ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/info")
    public Result<WareInfoVO> info(HttpServletRequest request, @RequestParam(name = "wareInfoId") Long wareInfoId) throws Exception {
        return Result.ok(wareInfoService.selectById(wareInfoId));
    }

    /**
     * 功能描述：删除仓库信息
     *
     * @param request     请求
     * @param wareInfoIds 批量删除的仓库信息ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/delete")
    public Result<Object> delete(HttpServletRequest request, @RequestBody List<Long> wareInfoIds) {
        return Result.delete(wareInfoService.delete(wareInfoIds));
    }

}
